﻿using HandyControl.Controls;
using BuyingSpree_HPV.Help;
using BuyingSpree_HPV.VM.Base;
using System;
using System.Collections.Generic;
using System.Text;

namespace BuyingSpree_HPV.VM
{
    public class EditCookieViewModel: DialogProcess
    {
        private string _header;
        public string Header
        {
            get { return _header; }
            set
            {
                _header = value;
                RaisePropertyChanged();
            }
        }

        
        private string _tk;
        public string Tk
        {
            get { return _tk; }
            set
            {
                _tk = value;
                RaisePropertyChanged();
            }
        }
        private string _cookie;
        public string Cookie
        {
            get { return _cookie; }
            set
            {
                _cookie = value;
                RaisePropertyChanged();
            }
        }
        /// <summary>
        /// 解析
        /// </summary>
        public override void Cancel()
        {
            try
            {
                string[] data = ParseUtil.ParseHeader(Header);
                if (data == null)
                {
                    MessageBox.Show("数据格式错误");
                }
                else
                {
                    Tk = data[0];
                    Cookie= data[1];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LoggerHelper.log.Info(DateTime.Now.ToString() + "异常-" + ex.StackTrace + "\r\n描述-" + ex.Message);
            }
        }

        public override void Save()
        {
            try
            {
                if (string.IsNullOrWhiteSpace(Tk) || string.IsNullOrWhiteSpace(Cookie))
                {
                    MessageBox.Show("请输入必要参数");
                    return;
                }
                base.Save();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LoggerHelper.log.Info(DateTime.Now.ToString() + "异常-" + ex.StackTrace + "\r\n描述-" + ex.Message);
            }
        }


    }
}
